Skip to content

@@ -- Add Express V4 Support to @salesforce/mrt-utilities package.#334

Merged
bendvc merged 6 commits intomainfrom
bendvc/mrt-utils-express-v4-support
Apr 10, 2026
Merged

@@ -- Add Express V4 Support to @salesforce/mrt-utilities package.#334
bendvc merged 6 commits intomainfrom
bendvc/mrt-utils-express-v4-support

Conversation

@bendvc
Copy link
Copy Markdown
Collaborator

@bendvc bendvc commented Apr 10, 2026

Here’s the updated PR description reflecting the new “import both versions” approach:

Summary

  • Add Express 4 compatibility for createMRTRequestProcessorMiddleware by forwarding async errors via next(err) while keeping the same public API.
  • Expand @salesforce/mrt-utilities Express peer range to support both v4 and v5, and run Express-related tests against both versions in a single test run.
  • Add real Express integration tests for query/header cleanup and static asset behavior to validate v4/v5 behavior.

Details

  • peerDependencies.express now allows ^4.18.2 || ^5.0.0, with dev aliases for both express4 and express5 used in tests.
  • Express-related tests are parameterized via a helper that loads both versions and runs the same test suite for each.
  • createMRTRequestProcessorMiddleware now forwards async errors via next(err) for Express 4 compatibility.
  • Integration tests cover query rewriting via x-mobify-querystring, cleanup middleware behavior, and static asset headers.

Test Plan

  • pnpm --filter @salesforce/mrt-utilities run build
  • pnpm --filter @salesforce/mrt-utilities run test

Notes

  • Root pnpm-lock.yaml updated due to new dev dependency aliases.

@bendvc bendvc requested a review from kieran-sf April 10, 2026 17:14
@bendvc bendvc requested a review from clavery as a code owner April 10, 2026 17:14
@github-actions github-actions Bot added the needs-3pl-review PR introduces net-new third-party dependencies and needs discussion label Apr 10, 2026
@bendvc bendvc changed the title @@ -- Add Excpress V4 Support to @salesforce/mrt-utilities package. @@ -- Add Express V4 Support to @salesforce/mrt-utilities package. Apr 10, 2026
Copy link
Copy Markdown
Collaborator

@clavery clavery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually @bendvc can you add a changeset (instructions in readme and claude/agents.md)

changeset triggers the version bump

https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/main/PUBLISHING.md#creating-a-changeset

@clavery clavery added 3pl-approved Maintainer approved net-new third-party dependency additions and removed needs-3pl-review PR introduces net-new third-party dependencies and needs discussion labels Apr 10, 2026
// Hand off to the next middleware
next();
// Apply custom query parameter parsing and forward errors via next()
processIncomingRequest(req, res)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the reason for the change here, I am just curious

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We made that change so this middleware works in Express 4.
Express 4 doesn’t always handle async errors, so we now call processIncomingRequest(...) and only call next() after it finishes, and if it fails we pass the error to next(err). This keeps the same behaviour but avoids unhandled promise errors. The function signature isn't changed, so we don't have a breaking change.

@bendvc bendvc merged commit 331db17 into main Apr 10, 2026
4 checks passed
@bendvc bendvc deleted the bendvc/mrt-utils-express-v4-support branch April 10, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3pl-approved Maintainer approved net-new third-party dependency additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants